<%@ page language="java"  import="org.json.*,web.rec.*,java.sql.*,com.microsoft.sqlserver.jdbc.*,java.util.Map,java.io.*" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>


<% 
// parameters: tables separated by comma, pkey, value

	String tableName = request.getParameter("qrystr");
	Map<String, String[]> map = request.getParameterMap();
	
	Connection conn = ResourceTool.getConnection();
	Statement stmt = conn.createStatement();
/*	
	StringBuilder query = new StringBuilder(200);
	StringBuilder whereList = new StringBuilder(200);
	

	query.append("SELECT " + map.get("pkey")[0] + " FROM ");
	whereList.append(" WHERE ");
	
	boolean first = true;
	
	for(String s: tableName){
		if(!first){
			query.append(",");
			whereList.append(" AND ");
		}else{
			first = false;
		}
		query.append(s);
		whereList.append( s + "." + map.get("pkey")[0] + "='" + map.get("value")[0]+"'");
		
	}
	
	query.append(whereList);
	
	System.out.println("query.jsp :" + query);
	*/
	ResultSet rs = stmt.executeQuery(tableName);
	JSONArray jsonArr = new JSONArray();
	
	
	while(rs.next()){
		jsonArr.put(rs.getString(1));
	}
	
	System.out.println(jsonArr.toString());
	out.append(jsonArr.toString());
	
//	ResultSet rs = stmt.executeQuery("SELECT * from " + tableName);
	
	
	
%>
